package com.insea.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class Facture extends BaseObject{

	private Long id;
	private String numFac;
	private Date dateFac;
	private String montant;
	private Boolean etat;
	private User user;

	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "numFac", nullable=false, unique=true)
	public String getNumFac() {
		return this.numFac;
	}

	public void setNumFac(String numFac) {
		this.numFac = numFac;
	}

	@Column(name = "dateFac")
	public Date getDateFac() {
		return this.dateFac;
	}

	public void setDateFac(Date dateFac) {
		this.dateFac = dateFac;
	}

	@Column(name = "montant")
	public String getMontant() {
		return this.montant;
	}

	public void setMontant(String montant) {
		this.montant = montant;
	}

	@Column(name = "etat")
	public Boolean getEtat() {
		return this.etat;
	}

	public void setEtat(Boolean etat) {
		this.etat = etat;
	}
	
	@ManyToOne
    @JoinColumn(name="USER_ID", nullable=false)
    public User getUser() { 
		return user; 
	}
	
	public void setUser(User user){
		this.user = user;
	}

	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof Facture))
			return false;
		Facture castOther = (Facture) other;

		return ((this.getNumFac() == castOther.getNumFac()) || (this
				.getNumFac() != null && castOther.getNumFac() != null && this
				.getNumFac().equals(castOther.getNumFac())))
				&& ((this.getDateFac() == castOther.getDateFac()) || (this
						.getDateFac() != null && castOther.getDateFac() != null && this
						.getDateFac().equals(castOther.getDateFac())))
				&& ((this.getMontant() == castOther.getMontant()) || (this
						.getMontant() != null && castOther.getMontant() != null && this
						.getMontant().equals(castOther.getMontant())))
				&& ((this.getEtat() == castOther.getEtat()) || (this.getEtat() != null
						&& castOther.getEtat() != null && this.getEtat()
						.equals(castOther.getEtat())));
	}

	public int hashCode() {
		int result = 17;

		result = 37 * result
				+ (getNumFac() == null ? 0 : this.getNumFac().hashCode());
		result = 37 * result
				+ (getDateFac() == null ? 0 : this.getDateFac().hashCode());
		result = 37 * result
				+ (getMontant() == null ? 0 : this.getMontant().hashCode());
		result = 37 * result
				+ (getEtat() == null ? 0 : this.getEtat().hashCode());
		return result;
	}

	@Override
	public String toString() {
		return numFac;
	}
}
